/**
 * Title: ExceptionHandler.java
 * @author wujin
 * @date 2020年1月2日
 * @version 1.0
 */
package com.pm.common.exception;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pm.common.Response;

import lombok.extern.slf4j.Slf4j;

/**
 * Title: ExceptionHandler
 * 
 * @author wujin
 * @date 2020年1月2日
 */
@ControllerAdvice
@Slf4j
public class ExceptionHandler {

	@org.springframework.web.bind.annotation.ExceptionHandler(CommonException.class)
	@ResponseBody
	public Response<?> handleCommonException(HttpServletRequest request, CommonException ex) {
		Response<?> response;
		log.error("exception code:{},msg:{}", ex.getResponse().getCode(), ex.getResponse().getMsg());
		response = new Response<Object>(ex.getResponse().getCode(), ex.getResponse().getMsg());
		return response;
	}

	@org.springframework.web.bind.annotation.ExceptionHandler(Exception.class)
	@ResponseBody
	public Response<?> handleException(HttpServletRequest request, Exception ex) {
		Response<?> response;
		log.error("exception error:{}", ex);
		response = new Response<Object>(ExpCodeState.network_error.getCode(), ExpCodeState.network_error.getMsg());
		return response;
	}
}
